﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Catsland.Core;

namespace Catsland.CatsPlugin
{
	class AttackInvoke : TriagerInvoker
	{
		public GameObject m_owner;
		public AttackInvoke()
		{
		}

        public void SetOwner(GameObject owner)
        {
            m_owner = owner;
        }

		public void EnterTrigger(Collider trigger, Collider invoker)
		{
		}

		public void InTrigger(Collider trigger, Collider invoker)
		{
			if (invoker.m_gameObject != m_owner) // make sure not talk to yourself
			{
                Breakable breakable = (Breakable)invoker.m_gameObject.GetComponent(typeof(Breakable).Name);
                
                if (breakable != null)
				{
					breakable.GetHurt(m_owner);
					// destroy itself
					Mgr<Scene>.Singleton._gameObjectList.RemoveItem(trigger.m_gameObject._guid);
				}
			}
		}

		public void ExitTrigger(Collider trigger, Collider invoker)
		{
		}
	}
}
